package com.example.diagnodroid.memoire;

import java.text.NumberFormat;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.example.diagnodroid.R;

public class ExternalMemoryActivity extends Activity {
	
	ProgressBar memoryBar;
	TextView infoMemoryText;
	
    StatFs stat;
    NumberFormat numberFormat;
    
    long memoryMax;
    long memoryAvailable;
    long memoryUsed;
    
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.external_memory_layout);

		memoryBar = (ProgressBar) findViewById(R.id.memory_bar);
		infoMemoryText = (TextView) findViewById(R.id.info_external_memory);
        stat = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());
		
        memoryMax = (stat.getBlockCount() * stat.getBlockSize()) / 1048576;
        memoryAvailable = (stat.getAvailableBlocks() * stat.getBlockSize()) / 1048576;
        memoryUsed = memoryMax - memoryAvailable;
                   
		infoMemoryText.append("\n mémoire totale : " + memoryMax + " MB\n" 
		+ "\n mémoire utilisée : " + memoryUsed + " MB\n" 
				+ "\n mémoire disponible : " + memoryAvailable + " MB\n");
		
		int percent_used = 	(int) ((memoryUsed * 100)/memoryMax);
				
		memoryBar.setMax(100);
		memoryBar.setProgress(percent_used);
	}
		
	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onStop() {
		super.onStop();
	}	

}